package com.example.yuhuaqiu.myqq;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * Created by Administrator on 2016/5/8.
 */
public class MeAdapter extends BaseAdapter{
    private Context ctx ;
    private List<Map<String,Object>> values;

    public  MeAdapter(Context ctx,List<Map<String,Object>> values){
        this.ctx = ctx;
        this.values = values;
    }

    @Override
    public int getCount() {
        return values.size();
    }

    @Override
    public Object getItem(int position) {
        return values.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView==null){

            convertView = LayoutInflater.from(ctx).inflate(R.layout.mes_list_line,null);
        }

        TextView img = (TextView) convertView.findViewById(R.id.line_img);
        TextView name = (TextView) convertView.findViewById(R.id.line_name);
        TextView mes = (TextView) convertView.findViewById(R.id.line_mes);
        TextView time = (TextView) convertView.findViewById(R.id.line_time);

        Map<String,Object> map = values.get(position);
        name.setText(map.get("name").toString());
        mes.setText(map.get("mes").toString());
        time.setText(map.get("time").toString());
        img.setBackgroundResource((Integer)map.get("img"));


        return convertView;
    }
}
